<?php
/**
 * Created by PhpStorm.
 * User: yuguozhen
 * Date: 16/8/1
 * Time: 上午11:28
 */
namespace models\Timer;
use library\DataLayer;

class TimersModel extends DataLayer{
    //计时统计
    public function Timer(){
        $prev_day = $this->time - 3600*24;
        $prev_start = date('Y-m-d 00:00:00',$prev_day);
        $prev_end = date('Y-m-d 23:59:59',$prev_day);

        $HOSPITAL = $this->Timer_HOSPITAL($prev_start,$prev_end);
        $ALL_HOSPITAL = $this->Timer_ALL_HOSPITAL($prev_start,$prev_end);
        $WEB_ACCOUNT = $this->Timer_WEB_ACCOUNT($prev_start,$prev_end);
        $INNER_WEB_ACCOUNT = $this->Timer_INNER_WEB_ACCOUNT($prev_start,$prev_end);
        $EXTERNAL_WEB_ACCOUNT = $this->Timer_EXTERNAL_WEB_ACCOUNT($prev_start,$prev_end);
        $GUIDANCE_CLASS = $this->Timer_GUIDANCE_CLASS($prev_start,$prev_end);
        $EXPERT_CLASS = $this->Timer_EXPERT_CLASS($prev_start,$prev_end);
        $NURSE_PUSH_CLASS = $this->Timer_NURSE_PUSH_CLASS($prev_start,$prev_end);
        $READ_PUSH_CLASS = $this->Timer_READ_PUSH_CLASS($prev_start,$prev_end);
        $QUESTION_PUSH_CLASS = $this->Timer_QUESTION_PUSH_CLASS($prev_start,$prev_end);

        if($HOSPITAL&&$ALL_HOSPITAL&&$WEB_ACCOUNT&&$INNER_WEB_ACCOUNT&&$EXTERNAL_WEB_ACCOUNT&&$GUIDANCE_CLASS&&$EXPERT_CLASS&&$NURSE_PUSH_CLASS&&$READ_PUSH_CLASS&&$QUESTION_PUSH_CLASS){
            return true;
        }else{
            return false;
        }
    }

    //统计医院--每日新增医院
    public function Timer_HOSPITAL($prev_start,$prev_end){
        $res = true;
        $str = "HOSPITAL:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord($str,$prev_start,$prev_end);

        if(!$ifrecode){
            //新增条数
            $Mhospital = new \models\Timer\Count\HospitalModel();
            $vaule = $Mhospital->NEW_HOSPITAL($prev_start,$prev_end);
            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'HOSPITAL');
            if(!$insert){
                $res = false;
            }
        }
//        return $str;
        return $res;
    }

    //统计医院--每日医院总数
    public function Timer_ALL_HOSPITAL($prev_start,$prev_end){
        $res = false;
        $str = "ALL_HOSPITAL:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('HOSPITAL',$prev_start,$prev_end,2);

        if(!$ifrecode){
            //新增条数
            $Mhospital = new \models\Timer\Count\HospitalModel();
            $vaule = $Mhospital->ALL_HOSPITAL();

//            数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'HOSPITAL',2);
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_WEB_ACCOUNT($prev_start,$prev_end){
        $res = false;
        $str = "WEB_ACCOUNT:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('WEB_ACCOUNT',$prev_start,$prev_end,1);

        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\WebAccountModel();
            $vaule = $Mweb->WEB_ACCOUNT($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'WEB_ACCOUNT');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_INNER_WEB_ACCOUNT($prev_start,$prev_end){
        $res = false;
        $str = "INNER_WEB_ACCOUNT:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('INNER_WEB_ACCOUNT',$prev_start,$prev_end);

        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\WebAccountModel();
            $vaule = $Mweb->INNER_WEB_ACCOUNT($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'INNER_WEB_ACCOUNT');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_EXTERNAL_WEB_ACCOUNT($prev_start,$prev_end){
        $res = false;
        $str = "EXTERNAL_WEB_ACCOUNT:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('EXTERNAL_WEB_ACCOUNT',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\WebAccountModel();
            $vaule = $Mweb->EXTERNAL_WEB_ACCOUNT($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'EXTERNAL_WEB_ACCOUNT');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_GUIDANCE_CLASS($prev_start,$prev_end){
//        $str = "GUIDANCE_CLASS:";
        $res = false;
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('GUIDANCE_CLASS',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\GuidanceClassModel();
            $vaule = $Mweb->GUIDANCE_CLASS($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'GUIDANCE_CLASS');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_EXPERT_CLASS($prev_start,$prev_end){
        $res = false;
        $str = "EXPERT_CLASS:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('EXPERT_CLASS',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\GuidanceClassPublicModel();
            $vaule = $Mweb->EXPERT_CLASS($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'EXPERT_CLASS');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
        return $res;
    }

    public function Timer_NURSE_PUSH_CLASS($prev_start,$prev_end){
        $res = false;
        $str = "NURSE_PUSH_CLASS:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('NURSE_PUSH_CLASS',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\NursePushClassModel();
            $vaule = $Mweb->NURSE_PUSH_CLASS($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'NURSE_PUSH_CLASS');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_READ_PUSH_CLASS($prev_start,$prev_end){
        $res = false;
        $str = "READ_PUSH_CLASS:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('READ_PUSH_CLASS',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\PatientInhospitalReadingDetailModel();
            $vaule = $Mweb->READ_PUSH_CLASS($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'READ_PUSH_CLASS');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

    public function Timer_QUESTION_PUSH_CLASS($prev_start,$prev_end){
        $res = false;
        $str = "QUESTION_PUSH_CLASS:";
        //是否记录过
        $Mstatistics = new \models\Timer\Count\StatisticsModel();
        $ifrecode = $Mstatistics->ifRecord('QUESTION_PUSH_CLASS',$prev_start,$prev_end);
        if(!$ifrecode){
            //新增条数
            $Mweb = new \models\Timer\Count\PatientInhospitalReadingDetailModel();
            $vaule = $Mweb->QUESTION_PUSH_CLASS($prev_start,$prev_end);

            //数据统计
            $Mnew_statistics = new \models\Timer\Insert\StatisticsModel();
            $insert = $Mnew_statistics->toInsert($prev_start,$vaule,'QUESTION_PUSH_CLASS');
            if($insert){
//                $str.= "ok";
                $res = true;
            }
        }else{
//            $str.= "err,has_record";
            $res = true;
        }
//        return $str;
        return $res;
    }

}